﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Maticsoft.DAL
{
	/// <summary>
	/// 数据访问类:supplier_bidplan_order
	/// </summary>
	public partial class supplier_bidplan_order
	{
		public supplier_bidplan_order()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("supplier_bidplan_order_id", "supplier_bidplan_order"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int supplier_bidplan_order_id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from supplier_bidplan_order");
			strSql.Append(" where supplier_bidplan_order_id=@supplier_bidplan_order_id");
			SqlParameter[] parameters = {
					new SqlParameter("@supplier_bidplan_order_id", SqlDbType.Int,4)
			};
			parameters[0].Value = supplier_bidplan_order_id;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(Maticsoft.Model.supplier_bidplan_order model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into supplier_bidplan_order(");
			strSql.Append("zbbh,wtgs,zbgs,pbrq,sprq,sid,proid,dpid,score,bj,pw,jdr,s_order)");
			strSql.Append(" values (");
			strSql.Append("@zbbh,@wtgs,@zbgs,@pbrq,@sprq,@sid,@proid,@dpid,@score,@bj,@pw,@jdr,@s_order)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@zbbh", SqlDbType.VarChar,200),
					new SqlParameter("@wtgs", SqlDbType.VarChar,200),
					new SqlParameter("@zbgs", SqlDbType.VarChar,200),
					new SqlParameter("@pbrq", SqlDbType.DateTime),
					new SqlParameter("@sprq", SqlDbType.DateTime),
					new SqlParameter("@sid", SqlDbType.Int,4),
					new SqlParameter("@proid", SqlDbType.NVarChar,50),
					new SqlParameter("@dpid", SqlDbType.Int,4),
					new SqlParameter("@score", SqlDbType.VarChar,20),
					new SqlParameter("@bj", SqlDbType.VarChar,20),
					new SqlParameter("@pw", SqlDbType.VarChar,200),
					new SqlParameter("@jdr", SqlDbType.VarChar,200),
					new SqlParameter("@s_order", SqlDbType.Int,4)};
			parameters[0].Value = model.zbbh;
			parameters[1].Value = model.wtgs;
			parameters[2].Value = model.zbgs;
			parameters[3].Value = model.pbrq;
			parameters[4].Value = model.sprq;
			parameters[5].Value = model.sid;
			parameters[6].Value = model.proid;
			parameters[7].Value = model.dpid;
			parameters[8].Value = model.score;
			parameters[9].Value = model.bj;
			parameters[10].Value = model.pw;
			parameters[11].Value = model.jdr;
			parameters[12].Value = model.s_order;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Maticsoft.Model.supplier_bidplan_order model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update supplier_bidplan_order set ");
			strSql.Append("zbbh=@zbbh,");
			strSql.Append("wtgs=@wtgs,");
			strSql.Append("zbgs=@zbgs,");
			strSql.Append("pbrq=@pbrq,");
			strSql.Append("sprq=@sprq,");
			strSql.Append("sid=@sid,");
			strSql.Append("proid=@proid,");
			strSql.Append("dpid=@dpid,");
			strSql.Append("score=@score,");
			strSql.Append("bj=@bj,");
			strSql.Append("pw=@pw,");
			strSql.Append("jdr=@jdr,");
			strSql.Append("s_order=@s_order");
			strSql.Append(" where supplier_bidplan_order_id=@supplier_bidplan_order_id");
			SqlParameter[] parameters = {
					new SqlParameter("@zbbh", SqlDbType.VarChar,200),
					new SqlParameter("@wtgs", SqlDbType.VarChar,200),
					new SqlParameter("@zbgs", SqlDbType.VarChar,200),
					new SqlParameter("@pbrq", SqlDbType.DateTime),
					new SqlParameter("@sprq", SqlDbType.DateTime),
					new SqlParameter("@sid", SqlDbType.Int,4),
					new SqlParameter("@proid", SqlDbType.NVarChar,50),
					new SqlParameter("@dpid", SqlDbType.Int,4),
					new SqlParameter("@score", SqlDbType.VarChar,20),
					new SqlParameter("@bj", SqlDbType.VarChar,20),
					new SqlParameter("@pw", SqlDbType.VarChar,200),
					new SqlParameter("@jdr", SqlDbType.VarChar,200),
					new SqlParameter("@s_order", SqlDbType.Int,4),
					new SqlParameter("@supplier_bidplan_order_id", SqlDbType.Int,4)};
			parameters[0].Value = model.zbbh;
			parameters[1].Value = model.wtgs;
			parameters[2].Value = model.zbgs;
			parameters[3].Value = model.pbrq;
			parameters[4].Value = model.sprq;
			parameters[5].Value = model.sid;
			parameters[6].Value = model.proid;
			parameters[7].Value = model.dpid;
			parameters[8].Value = model.score;
			parameters[9].Value = model.bj;
			parameters[10].Value = model.pw;
			parameters[11].Value = model.jdr;
			parameters[12].Value = model.s_order;
			parameters[13].Value = model.supplier_bidplan_order_id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int supplier_bidplan_order_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from supplier_bidplan_order ");
			strSql.Append(" where supplier_bidplan_order_id=@supplier_bidplan_order_id");
			SqlParameter[] parameters = {
					new SqlParameter("@supplier_bidplan_order_id", SqlDbType.Int,4)
			};
			parameters[0].Value = supplier_bidplan_order_id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string supplier_bidplan_order_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from supplier_bidplan_order ");
			strSql.Append(" where supplier_bidplan_order_id in ("+supplier_bidplan_order_idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Maticsoft.Model.supplier_bidplan_order GetModel(int supplier_bidplan_order_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 supplier_bidplan_order_id,zbbh,wtgs,zbgs,pbrq,sprq,sid,proid,dpid,score,bj,pw,jdr,s_order from supplier_bidplan_order ");
			strSql.Append(" where supplier_bidplan_order_id=@supplier_bidplan_order_id");
			SqlParameter[] parameters = {
					new SqlParameter("@supplier_bidplan_order_id", SqlDbType.Int,4)
			};
			parameters[0].Value = supplier_bidplan_order_id;

			Maticsoft.Model.supplier_bidplan_order model=new Maticsoft.Model.supplier_bidplan_order();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" supplier_bidplan_order_id,zbbh,wtgs,zbgs,pbrq,sprq,sid,proid,dpid,score,bj,pw,jdr,s_order ");
			strSql.Append(" FROM supplier_bidplan_order ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM supplier_bidplan_order ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.supplier_bidplan_order_id desc");
			}
			strSql.Append(")AS Row, T.*  from supplier_bidplan_order T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "supplier_bidplan_order";
			parameters[1].Value = "supplier_bidplan_order_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.supplier_bidplan_order DataRowToModel(DataRow row)
        {
            Maticsoft.Model.supplier_bidplan_order model = new Maticsoft.Model.supplier_bidplan_order();
            if (row != null)
            {
                if (row["supplier_bidplan_order_id"] != null && row["supplier_bidplan_order_id"].ToString() != "")
                {
                    model.supplier_bidplan_order_id = int.Parse(row["supplier_bidplan_order_id"].ToString());
                }
                if (row["zbbh"] != null)
                {
                    model.zbbh = row["zbbh"].ToString();
                }
                if (row["wtgs"] != null)
                {
                    model.wtgs = row["wtgs"].ToString();
                }
                if (row["zbgs"] != null)
                {
                    model.zbgs = row["zbgs"].ToString();
                }
                if (row["pbrq"] != null && row["pbrq"].ToString() != "")
                {
                    model.pbrq = DateTime.Parse(row["pbrq"].ToString());
                }
                if (row["sprq"] != null && row["sprq"].ToString() != "")
                {
                    model.sprq = DateTime.Parse(row["sprq"].ToString());
                }
                if (row["sid"] != null && row["sid"].ToString() != "")
                {
                    model.sid = int.Parse(row["sid"].ToString());
                }
                if (row["proid"] != null)
                {
                    model.proid = row["proid"].ToString();
                }
                if (row["dpid"] != null && row["dpid"].ToString() != "")
                {
                    model.dpid = int.Parse(row["dpid"].ToString());
                }
                if (row["score"] != null)
                {
                    model.score = row["score"].ToString();
                }
                if (row["bj"] != null)
                {
                    model.bj = row["bj"].ToString();
                }
                if (row["pw"] != null)
                {
                    model.pw = row["pw"].ToString();
                }
                if (row["jdr"] != null)
                {
                    model.jdr = row["jdr"].ToString();
                }
                if (row["s_order"] != null && row["s_order"].ToString() != "")
                {
                    model.s_order = int.Parse(row["s_order"].ToString());
                }
                if (row["bagnum"] != null)
                {
                    model.bagnum = row["bagnum"].ToString();
                }
                if (row["bagname"] != null)
                {
                    model.bagname = row["bagname"].ToString();
                }
                if (row["projectname"] != null)
                {
                    model.projectname = row["projectname"].ToString();
                }
                if (row["sname"] != null)
                {
                    model.sname = row["sname"].ToString();
                }

            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM Vsupplier_bidplan_order ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

		#endregion  ExtensionMethod
	}
}

